#!/bin/bash
# Copyright 2020 Tata Elxsi
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# For those usages not covered by the Apache License, Version 2.0 please
# contact: canonical@tataelxsi.onmicrosoft.com
#
# To get in touch with the maintainers, please contact:
# canonical@tataelxsi.onmicrosoft.com
##


USER=`action-get user`
PASSWORD=`action-get password`
DOMAIN=`action-get domain`
IMPLICIT=`action-get implicit`
mysql -D hss_db -u root -proot -e "INSERT INTO impu(identity, type, barring, user_state, id_sp, id_implicit_set, id_charging_info, wildcard_psi, display_name, psi_activation, can_register) VALUES ('sip:$USER@$DOMAIN',0,0,1,1,$IMPLICIT,1,'','',0,1)"
mysql -D hss_db -u root -proot -e "INSERT INTO imsu (name, scscf_name, diameter_name, id_capabilities_set, id_preferred_scscf_set)VALUES ('$USER','sip:scscf.$DOMAIN:6060','scscf.$DOMAIN',1,1)"

id_imsu=$(mysql -D hss_db -u root -proot -se "select id from imsu where name='$USER'")


mysql -D hss_db -u root -proot -e "INSERT INTO impi(id_imsu, identity, k, auth_scheme, default_auth_scheme, amf, op, sqn, ip, line_identifier, zh_uicc_type, zh_key_life_time, zh_default_auth_scheme) VALUES ($id_imsu,'$USER@$DOMAIN','$PASSWORD',127,1,'\0\0','\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0','000000000000','','',0,3600,1)"

id_impi=$(mysql -D hss_db -u root -proot -se "select id from impi where identity='$USER@$DOMAIN'")

id_impu=$(mysql -D hss_db -u root -proot -se "select id from impu where identity='sip:$USER@$DOMAIN'")


mysql -D hss_db -u root -proot -e "INSERT INTO impi_impu(id_impi, id_impu, user_state) VALUES ($id_impi,$id_impu,1)"

mysql -D hss_db -u root -proot -e "INSERT INTO impu_visited_network (id_impu, id_visited_network)VALUES ($id_impu,1)"
